package com.iwinding.ladygg.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.iwinding.ladygg.R;
import com.iwinding.ladygg.net.response.UserRp;
import com.iwinding.ladygg.utils.CommonUtil;
import com.iwinding.ladygg.utils.RoundedTransformation;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by hezhiyong on 2017/4/6.
 */

public class InvitationAdapter extends BaseAdapter<UserRp> {

    public InvitationAdapter(Context mContext, List mList) {
        super(mContext, mList);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.icane_adapter_invitation_item, null);
        }
        final UserRp userRp = mList.get(position);
        final ImageView icon = ViewHolder.get(convertView, R.id.icane_contact_img);
        final TextView name = ViewHolder.get(convertView, R.id.icane_contact_name);
        final Button invitation = ViewHolder.get(convertView, R.id.icane_invitation);

        if (!TextUtils.isEmpty(userRp.headImg)) {
            String url = CommonUtil.utf8Togb2312(userRp.headImg);
            Picasso.with(mContext).load(url).transform(new RoundedTransformation(9, 0)).into(icon);
        }
        name.setText(TextUtils.isEmpty(userRp.nickName) ? (TextUtils.isEmpty(userRp.uname) ? "" : userRp.uname) : userRp.nickName);

        invitation.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                SmsManager smsManager = SmsManager.getDefault();
//                String content = "我正在使用iCane, 关心身边老人，从我做起。下载: http://www.i-winding.com";
//                List<String> divideContents = smsManager.divideMessage(content);
//                for (String text : divideContents) {
//                    smsManager.sendTextMessage("150xxxxxxxx", null, text, sentPI, deliverPI);
//                }
                String content = mContext.getString(R.string.icane_send_sms);
                Intent mIntent = new Intent(Intent.ACTION_VIEW);
                mIntent.putExtra("address",userRp.mobile);
                mIntent.putExtra("sms_body", content);
                mIntent.setType("vnd.android-dir/mms-sms");
                mContext.startActivity(mIntent);
            }
        });
        return convertView;
    }
}
